package com.eclipse.training.swt.helloworld.listeners;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;

import com.eclipse.training.swt.helloworld.HelloWorld;
import com.eclipse.training.swt.helloworld.Messages;

public class MyShellListener implements ShellListener {

	@Override
	public void shellActivated(ShellEvent event) {
	}

	@Override
	public void shellClosed(ShellEvent event) {
		/*
		 * Open confirmation dialot
		 */
		MessageBox dialog = new MessageBox(Display.getDefault()
				.getActiveShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
		dialog.setText(Messages.getString("MyShellListener.0")); //$NON-NLS-1$
		dialog.setMessage(Messages.getString("MyShellListener.1")); //$NON-NLS-1$

		int returnCode = dialog.open();

		if (returnCode == SWT.OK)
			event.doit = true;
		else
			event.doit = false;
	}

	@Override
	public void shellDeactivated(ShellEvent event) {
	}

	@Override
	public void shellDeiconified(ShellEvent event) {
		HelloWorld.getStatusLine().setText(Messages.getString("MyShellListener.2")); //$NON-NLS-1$
	}

	@Override
	public void shellIconified(ShellEvent event) {
		HelloWorld.getStatusLine().setText(Messages.getString("MyShellListener.3")); //$NON-NLS-1$
	}

}
